<?php
function register_user($register_data){
   
   $fields = '`' . implode('`, `',array_keys($register_data)) . '`';
   $data = '\''. implode('\',\'',$register_data) . '\'';
  
   mysql_query("INSERT INTO `users`($fields) VALUES ($data)");
    
}
function user_data($ID){
    $data = array();
    $ID = (int)$ID;
    
    $func_num_args = func_num_args();
    $func_get_args = func_get_args();
  
   if($func_num_args > 1){
     unset($func_get_args[0]);
     $fields = '`' . implode('`,`',$func_get_args) . '`';     
     $data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `users` WHERE `ID` =$ID"));
     return $data;
    
   }
   
}

function logged_in(){
    return(isset($_SESSION['ID'])) ? true : false;
}


function user_exists($Username) {
    $Username = sanitize($Username);
    return (mysql_result(mysql_query("SELECT COUNT(`ID`) FROM `users` WHERE `Username` = '$Username'"), 0)==1) ? true : false;

}
function email_exists($User_email) {
    $User_email = sanitize($User_email);
    return (mysql_result(mysql_query("SELECT COUNT(`ID`) FROM `users` WHERE `User_email` = '$User_email'"), 0)==1) ? true : false;

}
function ID_from_username($Username){
    $Username = sanitize($Username);
    return mysql_result(mysql_query ("SELECT `ID` FROM `users` WHERE `Username` = '$Username'"), 0, 'ID' );
}


function login($Username, $Password){
    $ID= ID_from_username($Username);
    
    $Username = sanitize($Username);
    $Password = sanitize($Password);
    
    return (mysql_result(mysql_query("SELECT COUNT(`ID`) FROM `users` WHERE `Username` = '$Username' AND `Password` = '$Password'"), 0) == 1) ? $ID : false;
}
?>